package com.zmn.plat.admin.controller.push;

import java.util.List;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.push.inner.InnerDTO;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.plat.model.entity.inner.InnerQuery;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述: 站内信
 *
 * @author linfeng
 * @since 2020/05/20
 **/
@Slf4j
@RestController
@RequestMapping(value = "/push/inner/")
public class PushInnerListController extends PushInnerBaseController {

    /**
     * 描述: 站内信提醒页面
     *
     * @return org.springframework.web.servlet.ModelAndView
     * @author linfeng
     * @since 2020/5/20
     **/
    @RequestMapping(value = "remind")
    public ModelAndView remind() {
        InnerQuery query = new InnerQuery();
        Integer staffId = getMcStaff().getStaffId();
        query.setStaffId(staffId);
        query.setStatus(GlobalConsts.NO);
        query.setPageSize(pageSize);
        ModelAndView modelAndView = new ModelAndView("push/inner/remind");
        modelAndView.addObject("staffId", staffId);
        modelAndView.addObject("items", pushInfoService.listPageByQuery(query));
        return modelAndView;
    }

    @RequestMapping(value = "unReadMsgCount")
    public ResponseDTO getUnReadMsgCount() {
        InnerQuery query = new InnerQuery();
        Integer staffId = getMcStaff().getStaffId();
        query.setStaffId(staffId);
        query.setStatus(GlobalConsts.NO);
        Integer count = pushInfoService.countByQuery(query);
        return ResponseDTO.success(count, "操作成功");
    }

    @RequestMapping(value = "waitReadMsgCount")
    public ResponseDTO getWaitReadMsgCount() {
        InnerQuery query = new InnerQuery();
        Integer staffId = getMcStaff().getStaffId();
        query.setStaffId(staffId);
        query.setUnReadFlag(true);
        Integer count = pushInfoService.countByQuery(query);
        return ResponseDTO.success(count, "操作成功");
    }

    @RequestMapping(value = "listData")
    @ResponseBody
    public ResponseDTO listData() {
        InnerQuery query = new InnerQuery();
        Integer staffId = getMcStaff().getStaffId();
        query.setStaffId(staffId);
        query.setStatus(GlobalConsts.NO);
        query.setPageSize(pageSize);

        List<InnerDTO> innerDTOS = pushInfoService.listPageByQuery(query);

        return ResponseDTO.success(innerDTOS, "操作成功");
    }

}
